<template>
  <teleport :to="to">
    <Transition name="modal">
      <div v-if="show" class="modal-mask" @click="$emit('close')">
        <div class="modal-wrapper">
          <div class="modal-container" @click.stop>
            <slot></slot>
          </div>
        </div>
      </div>
    </Transition>
  </teleport>
</template>

<script setup lang="ts">
withDefaults(
  defineProps<{
    to?: string;
    show?: boolean;
  }>(),
  {
    to: 'body',
    show: false,
  }
);

// defineProps({
//   to: String,
//   show: Boolean
// });
</script>

<style scoped lang="scss">
.modal-mask {
  position: fixed;
  z-index: 9998;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: table;
  transition: opacity 0.3s ease;
}

.modal-container {
  width: 295px;
  margin: 0 auto;
  padding: 18px 24px 24px 24px;
  background: #fff;
  border-radius: 12px;
  transition: all 0.3s ease;
  position: relative;
}

.modal-wrapper {
  display: table-cell;
  vertical-align: middle;
}

.modal-enter-from,
.modal-leave-to {
  opacity: 0;
}

.modal-enter-from .modal-container,
.modal-leave-to .modal-container {
  -webkit-transform: scale(1.1);
  transform: scale(1.2);
}
</style>
